﻿
@{
    ViewBag.Title = "短信卡池";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<section class="content-header">
    <h1>
        短信卡池管理
        <small></small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i>主页</a></li>
        <li class="active">短信卡池列表</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box box-primary">
                <div class="box-header">
                    <form id="search-form" class="form-inline">
                        <div class="form-group">
                            <label>卡所有人手机号</label>
                            <input type="text" class="form-control" style="width:100px;" maxlength="11" name="ownerTel" id="ownerTel" autocomplete="off" />
                        </div>
                        <div data-toggle="distpicker" class="form-group">
                            <label>卡所有人姓名</label>
                            <input type="text" class="form-control" style="width:100px;" maxlength="11" name="ownerName" id="ownerName" autocomplete="off" />
                        </div>
                        @*<div class="form-group">
                            <label>通信制式类型</label>
                            <select id="selType" name="selType" class="form-control">
                                <option value="0">全部</option>
                                <option value="1">移动</option>
                                <option value="2">联通</option>
                                <option value="3">电信</option>
                            </select>
                        </div>*@
                        <div class="form-group">
                            <label>状态</label>
                            <select id="selStatus" name="selStatus" class="form-control">
                                <option value="-1">全部</option>
                                <option value="0">正常</option>
                                <option value="1">已删除</option>
                               
                            </select>
                        </div>
                        <div class="form-group">
                            <label>创建时间</label>
                            <input type="text" class="form-control" style="width:100px;" name="BCreateDate" id="BCreateDate" autocomplete="off" />
                        </div>
                        <div class="form-group">
                            <input type="text" class="form-control" style="width:100px;" name="ECreateDate" id="ECreateDate" autocomplete="off" />
                        </div>
                        <div class="form-group">
                            <button type="button" class="btn btn-success btn-sm" id="btnSearch">查找</button>
                            <button type="button" class="btn btn-success btn-sm" id="btnEnable">启用</button>
                            <button type="button" class="btn btn-success btn-sm" id="btnProhibit">禁用</button>
                            @*<button type="button" class="btn btn-success btn-sm" id="btnRefresh">换卡作作</button>*@
                            <button class="btn btn-primary" id="btnAdd" type="button">添加</button>
                        </div>

                        <h3 class="box-title"></h3>
                    </form>
                </div>
                <!-- /.box-header -->
                <div class="box-body table-responsive no-padding">
                    <table class="table table-bordered table-hover body-table-head">
                        <thead>
                            <tr>
                                <th>
                                    <input type="checkbox" id="selPageAll" />
                                </th>
                                <th>
                                    卡所有人姓名
                                </th>
                                <th>
                                    卡所有人手机号
                                </th>
                                @*<th>
                                    端口号
                                </th>*@
                                @*<th>
                                    通信制式类型
                                </th>*@
                                <th>
                                    每小时可发送短信数量
                                </th>
                                <th>
                                    每天可发送短信数量
                                </th>
                                <th>
                                    创建时间
                                </th>
                                <th>
                                    状态
                                </th>
                                <th class="t_c">
                                    操作
                                </th>
                            </tr>
                        </thead>
                        <tbody id="tbodylist"></tbody>
                    </table>
                    <div class="no-data" id="nodata" style="display:none;">
                        <div class="img-box"></div>
                        <div class="text">暂无数据</div>
                    </div>
                </div>
                <div class="box-footer clearfix ">
                    <ul id="pagination" class="pagination pagination-sm no-margin pull-right"></ul>
                </div>
                <!-- /.box-body -->
                <!-- /.box -->
            </div>
        </div>
    </div>
</section>
@section scriptsBottom{
    <script src="@Url.Content("~/lib/art-template/template-web.js")"></script>
    <script id="dataItemTpl" type="text/html">
        {{each rows}}
        <tr>
            <td><input type="checkbox" name="chkItem" value="{{$value.CardID}}"/></td>
            <td class="title">
                {{$value.OwnerName}}
            </td>
            <td class="title">
                {{$value.OwnerMobile}}
            </td>
            @*<td class="title">
                {{$value.PortNumber}}
            </td>*@
            @*<td>
                {{$value.TelTypeTxt}}
            </td>*@
            <td>
                {{$value.CountPerHour}}
            </td>
            <td>
                {{$value.CountPerDay}}
            </td>
            <td>
                {{$value.CreatedTime}}
            </td>
            <td>
                {{$value.StatusText}}
            </td>
           
            <td class="t_c">
                <button type="button" class="btn btn-info btn-xs" onclick="edit('{{$value.CardID}}')">修改</button>
                {{if $value.IsDeleted==0}}
                <button type="button" class="btn btn-danger btn-xs" onclick="del('{{$value.CardID}}')">禁用</button>
                {{else}}
                <button type="button" class="btn btn-danger btn-xs" onclick="del('{{$value.CardID}}')">启用</button>
                {{/if}}
            </td>
        </tr>
        {{/each}}
    </script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#BCreateDate").datepicker({
                language: "zh-CN",
                autoclose: true,//选中之后自动隐藏日期选择框
                format: "yyyy-mm-dd"//日期格式，
            });
            $("#ECreateDate").datepicker({
                language: "zh-CN",
                autoclose: true,//选中之后自动隐藏日期选择框
                format: "yyyy-mm-dd"//日期格式，
            });

            $("#btnSearch").click(function () {
                pageIndex = 1;
                list();
            });

            list();

            $("#btnAdd").click(function () {
                var url = '@Url.Action("CardEdit", "Sms")';
                location.href = url;
            });

            initCheckbox(); 

            $("#btnEnable").click(function () {
                var url = '@Url.Action("EnableCardByIds", "Sms")';
                var arr = [];
                $("#tbodylist").find('input[type="checkbox"]:checked').each(function () {
                    arr.push($(this).val());
                });
                if (arr.length == 0) {
                    BMCW.alert("请选择要启用的短信卡");
                    return;
                }

             
                BMCW.DataConfirm("确认执行批量启用操作吗?", function () {
                    BMCW.ajax({
                        url: url,
                        type: "POST",
                        data: {
                            ids: arr
                        },
                        success: function (o) {
                            if (o.status == 0) {
                                BMCW.msg("批量启动成功", function () {
                                    list();
                                });

                            } else {
                                BMCW.alert(o.message);
                            }
                        }
                    });
                })
            });

            $("#btnProhibit").click(function () {
                var url = '@Url.Action("ProhibitCardByIds", "Sms")';
                var arr = [];
                $("#tbodylist").find('input[type="checkbox"]:checked').each(function () {
                    arr.push($(this).val());
                });
                if (arr.length == 0) {
                    BMCW.alert("请选择要禁用的短信卡");
                    return;
                }


                BMCW.DataConfirm("确认执行批量禁用操作吗?", function () {
                    BMCW.ajax({
                        url: url,
                        type: "POST",
                        data: {
                            ids: arr
                        },
                        success: function (o) {
                            if (o.status == 0) {
                                BMCW.msg("批量禁用成功", function () {
                                    list();
                                });

                            } else {
                                BMCW.alert(o.message);
                            }
                        }
                    });
                })
            });

            $("#btnRefresh").on("click", function () {
                $(this).attr("disabled", "disabled");
                var orgText = $(this).text();
                $(this).text("正在执行..");
                var url = '@Url.Action("ReplaceCard", "Sms")';
                BMCW.DataConfirm("确认要执行此操作吗?", function() {
                    BMCW.ajax({
                        url: url,
                        type: "POST",
                        data: {
                            
                        },
                        success: function(o) {
                            if (o.status == 0) {
                                BMCW.msg("操作成功", function() {
                                    
                                });

                            } else {
                                BMCW.alert(o.message);
                            }
                        },
                        complete:function() {
                            $(this).removeAttr("disabled");
                            $(this).Text(orgText);
                        }
                    });
                });
            });
        });

        //初始化全选和全部取消操作
        function initCheckbox() {

            $('#selPageAll').click(function() {
                $('input[type="checkbox"]').prop("checked", this.checked);
            });
        }

        //页码
        var pageIndex = 1;
        //查询
        function list() {

            var url = '@Url.Action("SmsCardList", "Sms")' + "?page=" + pageIndex+"&rows=10";
            //查询列表
            BMCW.ajax({
                url: url,
                type: 'POST',
                dataType: "json",
                data: {
                    OwnerTel: $("#ownerTel").val(),
                    OwnerName: $("#ownerName").val(),
                    //TelType: $("#selType").val(),
                    Status: $("#selStatus").val(),
                    StartDate: $("#BCreateDate").val(),
                    EndDate: $("#ECreateDate").val()
                },
                success: function (dt) {
                    if (dt.total < 1) {
                        $("#nodata").show();
                        document.getElementById('tbodylist').innerHTML = "";
                        return;
                    }
                    $("#nodata").hide();
                    //模板渲染
                    var data = dt.rows;
                    var html = template('dataItemTpl', dt);
                    document.getElementById('tbodylist').innerHTML = html;
                    $("#tbodylist").find('tr').each(function () {
                        $(this).find('input[type="checkbox"]').click(function () {
                            if ($("#tbodylist").find('input[type="checkbox"]:checked').length == $("#tbodylist").find('input[type="checkbox"]').length) {
                                $('#selPageAll').prop("checked", true)
                            } else {
                                $('#selPageAll').prop("checked", false)
                            }
                        })

                    });
                    //分页显示
                    $('#pagination').twbsPagination("destroy");
                    $('#pagination').twbsPagination({
                        totalItems: dt.total,
                        visiblePages: 10,
                        pageSize: 10,
                        startPage: parseInt(pageIndex),
                        onPageClick: function (event, page) {
                            pageIndex = page;
                            list();
                        }
                    });
                }
            });
        }

        //用户详情
        function edit(userid) {
            var url = '@Url.Action("CardEdit", "Sms")' + "?carid=" + userid;
            location.href = url;
        }

        function del(id) {
            var url = '@Url.Action("DelCard", "Sms")'
            BMCW.DataConfirm("确认要执行此操作吗?", function () {
                BMCW.ajax({
                    url: url,
                    type: "POST",
                    data: {
                        id: id
                    },
                    success: function (o) {
                        if (o.status == 0) {
                            BMCW.msg("操作成功", function () {
                                list();
                            });

                        } else {
                            BMCW.alert(o.message);
                        }
                    }
                });
            })
        }
    </script>
}






